// 序列化时间 年月日时分秒
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

// 序列化数字
const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

// obj转成url
const formatObjToUrl = obj => {
  let arr = [];
  for(var key in obj) {
      arr.push(key + '=' +obj[key])
  }
  return '?' + arr.join('&');
}

// 随机颜色类
function RandomColor(){
  this.r = Math.floor(Math.random()*255);
  this.g = Math.floor(Math.random()*255);
  this.b = Math.floor(Math.random()*255);
  this.color = 'rgba('+ this.r +','+ this.g +','+ this.b +', 1)';
}
module.exports = {
  formatTime,
  formatObjToUrl,
  RandomColor
}
